<!DOCTYPE html>
<html lang="en">
<head>
    
    <meta charset="utf-8">
    <title>data/calculate.js - Documentation</title>
    
    
    <script src="scripts/prettify/prettify.js"></script>
    <script src="scripts/prettify/lang-css.js"></script>
    <!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="styles/prettify.css">
    <link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
    <script src="scripts/nav.js" defer></script>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>

<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
  <div class="navicon"></div>
</label>

<label for="nav-trigger" class="overlay"></label>

<nav >
    
    <h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="color.html">color</a><ul class='methods'><li data-type='method'><a href="color.html#.setColorOpacity">setColorOpacity</a></li></ul></li><li><a href="data.html">data</a><ul class='methods'><li data-type='method'><a href="data.html#.getMax">getMax</a></li><li data-type='method'><a href="data.html#.getMin">getMin</a></li><li data-type='method'><a href="data.html#.getTotal">getTotal</a></li><li data-type='method'><a href="data.html#.toArray">toArray</a></li><li data-type='method'><a href="data.html#.toJson">toJson</a></li></ul></li><li><a href="date.html">date</a><ul class='methods'><li data-type='method'><a href="date.html#.dateFormat">dateFormat</a></li><li data-type='method'><a href="date.html#.getDate">getDate</a></li></ul></li><li><a href="is.html">is</a><ul class='methods'><li data-type='method'><a href="is.html#.isIDCard">isIDCard</a></li><li data-type='method'><a href="is.html#.isPhone">isPhone</a></li><li data-type='method'><a href="is.html#.isType">isType</a></li></ul></li></ul>
</nav>

<div id="main">
    
    <h1 class="page-title">data/calculate.js</h1>
    

    



    
    <section>
        <article>
            <pre class="prettyprint source linenums"><code>/**
 * 获取一组数的最大值
 * 
 * @memberof data
 * 
 * @param {Array} value 数据数组(必传)
 * &lt;br /> 支持格式：[1,2,3] 和
 * &lt;br /> [{name:'zhangsan',value:10},{name:'lisi',value:20}]
 * 
 * @param {String} key json数据的 key 值（可选）
 * &lt;br /> 默认为 value 
 * 
 * @returns 数据最大值
 * 
 * @example  
 * getMax([1,2,3]); // 3
 * getMax([{name:'zhangsan',value:10},{name:'lisi',value:20}],value); // 20
 */
function getMax(value, key) {
    let v = value;
    const {
        isType
    } = this
    key = key || 'value'
    let max = - Infinity;
    if (v instanceof Array) {
        v.forEach(item => {
            if (isType(item, 'Object')) {
                max = (item[key] || - Infinity) > max ? item[key] : max
            }
            if (isType(item, 'Number')) {
                max = (item || - Infinity) > max ? item : max
            }
        })
    }
    return max
}
/**
 * 获取一组数的最小值
 * 
 * @memberof data
 * 
 * @param {Array} value 数据数组(必传)
 * &lt;br /> 支持格式：[1,2,3] 和
 * &lt;br /> [{name:'zhangsan',value:10},{name:'lisi',value:20}]
 * 
 * @param {String} key json数据的 key 值（可选）
 * &lt;br /> 默认为 value 
 * 
 * @returns 数据最小值
 * 
 * @example  
 * getMin([1,2,3]); // 1
 * getMin([{name:'zhangsan',value:10},{name:'lisi',value:20}],value); // 10
 */
function getMin(value, key) {
    let v = value;
    const {
        isType
    } = this
    key = key || 'value'
    let min = Infinity;
    if (v instanceof Array) {
        v.forEach(item => {
            if (isType(item, 'Object')) {
                min = (item[key] || Infinity) &lt; min ? item[key] : min
            }
            if (isType(item, 'Number')) {
                min = (item || Infinity) &lt; min ? item : min
            }
        })
    }
    return min
}
/**
 * 获取一组数的总值
 * 
 * @memberof data
 * 
 * @param {Array} value 数据数组(必传)
 * &lt;br /> 支持格式：[1,2,3] 和
 * &lt;br /> [{name:'zhangsan',value:10},{name:'lisi',value:20}]
 * 
 * @param {String} key json数据的 key 值（可选）
 * &lt;br /> 默认为 value 
 * 
 * @returns 数据总值
 * 
 * @example  
 * getTotal([1,2,3]); // 6
 * getTotal([{name:'zhangsan',value:10},{name:'lisi',value:20}],value); // 30
 */
function getTotal(value, key) {
    let v = value;
    const {
        isType
    } = this
    key = key || 'value'
    let total = 0;
    if (v instanceof Array) {
        v.forEach(item => {
            if (isType(item, 'Object')) {
                total += item[key] || 0
            }
            if (isType(item, 'Number')) {
                total += item || 0
            }
        })
    }
    return total 
}
module.exports.getMax = getMax
module.exports.getMin = getMin
module.exports.getTotal = getTotal
</code></pre>
        </article>
    </section>




    
    
</div>

<br class="clear">

<footer>
    Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.6</a> on Wed Feb 24 2021 16:40:34 GMT+0800 (中国标准时间) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
<script src="scripts/polyfill.js"></script>
<script src="scripts/linenumber.js"></script>



</body>
</html>
